package cn.funeralobjects.upms.converter;

import org.springframework.util.StringUtils;

import javax.persistence.AttributeConverter;

/**
 * groupPath的路径转换器
 *
 * @author FuneralObjects
 * Create date: 2019-08-10 15:20
 */
public class GroupPathConverter implements AttributeConverter<String[], String> {
    @Override
    public String convertToDatabaseColumn(String[] attribute) {
        if (attribute == null) {
            return "";
        }
        return String.join(":", attribute);
    }

    @Override
    public String[] convertToEntityAttribute(String dbData) {
        if (StringUtils.isEmpty(dbData)) {
            return new String[0];
        }
        return dbData.split(":");
    }
}
